<?php
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ('fix_all' == $op) {
	pdo_query("REPAIR TABLE  " . tablename('bsht_tbk_all_item'));
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}
if ('fix_allcaiji' == $op) {
	pdo_query("REPAIR TABLE  " . tablename('bsht_tbk_all_caiji'));
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}
if ('delall_caiji' == $op) {
	$list = pdo_fetch("SELECT * FROM " . tablename($this->tablecaijiall) . " WHERE uniacid = '{$_W['uniacid']}'");
	if ($list) {
		pdo_delete($this->tablecaijiall, array('uniacid' => $_W['uniacid']));
		message('操作成功！', $this->createWebUrl('listcaijiall', array('op' => 'display')), 'success');
	} else {
		message('未发现已采集商品！', $this->createWebUrl('listcaijiall', array('op' => 'display')), 'error');
	}
}
if ('show_none' == $op) {
	if (empty($_GPC['page']) || $_GPC['page'] <= 0) {
		$_GPC['page'] = 1;
	}
	$pindex = max(1, intval($_GPC['page']));
	$psize = 200;
	$list = pdo_fetch("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' AND status=0 LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	if ($list) {
		pdo_delete($this->tableitemall, array('uniacid' => $_W['uniacid'], 'status' => 0));
		$newpage = $pindex++;
		if (empty($_GPC['no'])) {
			$_GPC['no'] = 1;
		}
		$newpage = $_GPC['no'] + 1;
		message('即将清理第' . $newpage . '页（每页200条），请稍后。。。', $this->createWebUrl('itemall_op', array('op' => 'show_none', 'page' => $newpage, 'no' => $newpage)), 'success');
	} else {
		message('未发现已下架商品！', $this->createWebUrl('listitemall', array('op' => 'display')), 'error');
	}
}
if ('xiajia_daoqi' == $op) {
	if (empty($_GPC['page']) || $_GPC['page'] <= 0) {
		$_GPC['page'] = 1;
	}
	$pindex = max(1, intval($_GPC['page']));
	$psize = 200;
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	if ($list) {
		foreach ($list as $key => $value) {
			if (time() - strtotime($list[$key]['itemyhj_etime']) >= 86400 && !empty($list[$key]['itemyhj_url'])) {
				$data = array('status' => 0,);
				pdo_update($this->tableitemall, $data, array('id' => $list[$key]['id']));
			}
		}
		$newpage = $pindex++;
		if (empty($_GPC['no'])) {
			$_GPC['no'] = 1;
		}
		$newpage = $_GPC['no'] + 1;
		message('即将清理第' . $newpage . '页（每页200条），请稍后。。。', $this->createWebUrl('itemall_op', array('op' => 'xiajia_daoqi', 'page' => $newpage, 'no' => $newpage)), 'success');
	}
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}
if ('del_daoqi' == $op) {
	if (empty($_GPC['page']) || $_GPC['page'] <= 0) {
		$_GPC['page'] = 1;
	}
	$pindex = max(1, intval($_GPC['page']));
	$psize = 200;
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	if ($list) {
		foreach ($list as $key => $value) {
			if (time() - strtotime($list[$key]['itemyhj_etime']) >= 86400 && !empty($list[$key]['itemyhj_url'])) {
				pdo_delete($this->tableitemall, array('uniacid' => $_W['uniacid'], 'id' => $list[$key]['id']));
				pdo_delete($this->tablefav, array('uniacid' => $_W['uniacid'], 'itemid' => $list[$key]['id']));
			}
		}
		$newpage = $pindex++;
		if (empty($_GPC['no'])) {
			$_GPC['no'] = 1;
		}
		$newpage = $_GPC['no'] + 1;
		message('即将清理第' . $newpage . '页（每页200条），请稍后。。。', $this->createWebUrl('itemall_op', array('op' => 'del_daoqi', 'page' => $newpage, 'no' => $newpage)), 'success');
	}
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}
if ('xiajia_none' == $op) {
	if (empty($_GPC['page']) || $_GPC['page'] <= 0) {
		$_GPC['page'] = 1;
	}
	$pindex = max(1, intval($_GPC['page']));
	$psize = 200;
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	if ($list) {
		foreach ($list as $key => $value) {
			if (empty($list[$key]['itemyhj_url'])) {
				$data = array('status' => 0,);
				pdo_update($this->tableitemall, $data, array('id' => $list[$key]['id']));
			}
		}
		$newpage = $pindex++;
		if (empty($_GPC['no'])) {
			$_GPC['no'] = 1;
		}
		$newpage = $_GPC['no'] + 1;
		message('即将清理第' . $newpage . '页（每页200条），请稍后。。。', $this->createWebUrl('itemall_op', array('op' => 'xiajia_none', 'page' => $newpage, 'no' => $newpage)), 'success');
	}
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}
if ('del_none' == $op) {
	if (empty($_GPC['page']) || $_GPC['page'] <= 0) {
		$_GPC['page'] = 1;
	}
	$pindex = max(1, intval($_GPC['page']));
	$psize = 200;
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
	if ($list) {
		foreach ($list as $key => $value) {
			if (empty($list[$key]['itemyhj_url'])) {
				pdo_delete($this->tableitemall, array('uniacid' => $_W['uniacid'], 'id' => $list[$key]['id']));
				pdo_delete($this->tablefav, array('uniacid' => $_W['uniacid'], 'itemid' => $list[$key]['id']));
			}
		}
		$newpage = $pindex++;
		if (empty($_GPC['no'])) {
			$_GPC['no'] = 1;
		}
		$newpage = $_GPC['no'] + 1;
		message('即将清理第' . $newpage . '页（每页200条），请稍后。。。', $this->createWebUrl('itemall_op', array('op' => 'del_none', 'page' => $newpage, 'no' => $newpage)), 'success');
	}
	message('操作成功！', $this->createWebUrl('listitemall', array('op' => 'display')), 'success');
}